<?php
	
	class Login extends arfaController
	{
		public function __construct()
		{
			parent::__construct();
			$this->load->model("login_model");
		}
		public function index()
		{
			$this->form_validation->set_rules('username','Username','required|xss_clean');
			$this->form_validation->set_rules('password','Password','required');
			if($this->form_validation->run() == FALSE)
			{
				$this->load->view("login");
			}
			else
			{
				$username	= $this->input->post("username");
				$password	= md5($this->input->post("password"));
				
				$query = $this->login_model->get_by(array('USERNAME' => $username, 'PASSWORD' => $password));
				if(! empty($query))
				{
					$this->session->set_userdata('id_akun', $query[0]['ID_AKUN']);
					$this->session->set_userdata('username', $query[0]['USERNAME']);
					$this->session->set_userdata('status_login', TRUE);

					redirect('ruas_jalan/grid_rj');
				}
				else
				{
					$this->session->set_flashdata('message', 'Username atau Password yang anda masukan salah');
					redirect('login');
				}
			}
		}
		public function logout()
		{
			$this->session->sess_destroy();
			$this->index();
			return TRUE;
		}
	}